package com.couldsail.takeaway.controller.user;

import com.couldsail.takeaway.common.result.Result;
import com.couldsail.takeaway.pojo.dto.ProductsDTO;
import com.couldsail.takeaway.pojo.entity.Banner;
import com.couldsail.takeaway.pojo.vo.BannerVO;
import com.couldsail.takeaway.service.BannerService;
import com.couldsail.takeaway.service.ProductsService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController("ProductsController")
@RequestMapping("/user/products")
@RequiredArgsConstructor
@CrossOrigin(origins = "*") // 允许所有来源的请求跨域
@Api(tags = "商品管理")
public class ProductsController {
    private final ProductsService productsService;
    private final BannerService bannerService;
    /**
     * 获取商品信息
     * @param category_id
     */
    @GetMapping
    public Result<List<ProductsDTO>> getProducts(String category_id){
        log.info("获取商品信息{}",category_id);
        return Result.success(productsService.getProducts(category_id));
    }
    /**
     * 获取广告banner图
     */
    @GetMapping("/banner")
    public Result<List<BannerVO>> getBanner(String id){
        log.info("获取轮播图{}",id);
        return Result.success(bannerService.getBannerList(id));
    }
}
